import baseUrl from "./baseUrl.js";
import request from "@/utils/http.request.js";

const user = {
    /**
     * 用户名登录
     * @param userName 用户名
     * @param password 密码
     * @param verifyCode 验证码
     * @param uuid 
     * @param _response
     * @param _finally
     * @return {*|void}
     */
    login(userName, password, verifyCode, uuid, _response, _finally = null) {
        return request.postWithForm(`${baseUrl.user}/login`, { userName: userName, password: password, verifyCode: verifyCode, uuid: uuid }, _response, _finally);
    },
    /**
     * 注销、登出。
     * @param _response 
     * @param _finally 
     * @returns 
     */
    logout(_response, _finally = null) {
        return request.getWithoutParam(`${baseUrl.user}/logout`, _response, _finally);
    },
    /**
     * 获取用户信息。
     * @param userId 用户Id
     * @param _response 
     * @param _finally 
     * @returns 
     */
    get(userId, _response, _finally = null) {
        return request.getWithoutParam(`${baseUrl.user}/${userId}`, _response, _finally);
    },
    /**
     * 获取用户列表
     * @param pageIndex 当前页
     * @param pageSize
     * @param keyword 关键字
     * @param status 状态
     * @param roleId 角色Id
     * @param _response 
     * @param _finally 
     * @returns 
     */
    pageList(pageIndex, pageSize, keyword, status, roleId, _response, _finally = null) {
        return request.get(`${baseUrl.user}/pagelist`, { pageIndex: pageIndex, pageSize: pageSize, keyword: keyword, status: status, roleId: roleId }, _response, _finally);
    },
    /**
     * 添加用户信息
     * @param roleId 角色Id
     * @param userName 用户名称
     * @param nickName 昵称
     * @param email 邮箱
     * @param tel 电话
     * @param bak 备注
     * @param _response 
     * @param _finally 
     * @returns 
     */
    add(roleId, userName, nickName, email, tel, bak, _response, _finally = null) {
        return request.postWithJson(`${baseUrl.user}`, { roleId: roleId, userName: userName, nickName: nickName, email: email, tel: tel, bak: bak }, _response, _finally);
    },
    /**
     * 修改用户信息
     * @param userId 用户Id
     * @param roleId 角色Id
     * @param nickName 昵称
     * @param email 邮箱
     * @param tel 电话
     * @param bak 备注
     * @param status 状态
     * @param _response 
     * @param _finally 
     * @returns 
     */
    edit(userId, roleId, nickName, email, tel, bak, status, _response, _finally = null) {
        return request.putWithJson(`${baseUrl.user}`, { userId: userId, roleId: roleId, nickName: nickName, email: email, tel: tel, bak: bak, status: status }, _response, _finally);
    },
    /**
     * 重置用户密码
     * @param userId 用户id     
     * @param _response 
     * @param _finally 
     * @returns 
     */
    resetPwd(userId, _response, _finally = null) {
        return request.put(`${baseUrl.user}/resetpwd/${userId}`, _response, _finally);
    },
    /**
     * 修改自己的用户信息
     * @param nickName 昵称
     * @param email 邮箱
     * @param tel 电话
     * @param _response 
     * @param _finally 
     * @returns 
     */
    editInfo(nickName, email, tel, _response, _finally = null) {
        return request.putWithJson(`${baseUrl.user}/info`, { nickName: nickName, email: email, tel: tel }, _response, _finally);
    },
    /**
     * 修改自己的头像
     * @param fileObj 文件对象信息。
     * @param _response 
     * @param _finally 
     * @returns 
     */
    editAvatar(fileObj, _response, _finally = null) {
        return request.putWithJson(`${baseUrl.user}/avatar`, fileObj, _response, _finally);
    },
    /**
     * 修改密码。
     * @param oldPassword 旧密码
     * @param newPassword 新密码
     * @param _response 
     * @param _finally 
     * @returns 
     */
    editPassword(oldPassword, newPassword, _response, _finally = null) {
        return request.putWithJson(`${baseUrl.user}/change`,
            { oldPassword: oldPassword, newPassword: newPassword }, _response, _finally);
    },
    /**
     * 删除用户
     * @param userId 用户id
     * @param _response 
     * @param _finally 
     * @returns 
     */
    delete(userId, _response, _finally = null) {
        return request.deleteWithouParam(`${baseUrl.user}/${userId}`, _response, _finally)
    }

};

export default user;